<template>
  <div>
    <el-card class="box-card">
      <el-form
        :inline="true"
        @keyup.enter.native="getExportDispatchList()"
        class="dadeFrom"
      >
        <el-date-picker
          class="inputData"
          placeholder="选择日期"
          v-model="valuetimes"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          clearable
        >
        </el-date-picker>
        选择场景:<el-select
          v-model="titleval"
          clearable
          style="width: 300px"
          placeholder="选取推送场景"
          @change="changeTitleCon()"
        >
          <el-option
            :label="item.dictName"
            :value="item.dictValue"
            v-for="item in titleList"
            :key="item.id"
          ></el-option>
        </el-select>
        <el-button type="primary" @click="getpolling">查询</el-button>
        <el-button type="success" @click="exportGet()">下载</el-button>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin-top: 10px">
      <el-table
        :data="dataList"
        style="width: 100%"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(12,42,98, .9)"
      >
        <el-table-column
          label="分公司"
          prop="cityName"
          align="center"
          width="100"
        >
        </el-table-column>
        <el-table-column label="发送规模" align="center">
          <el-table-column
            label="合计"
            prop="pushSumCount"
            align="center"
            width="100"
          >
            <!-- <template slot-scope="scope">
              <span v-html="getFaSong(scope.row)"></span>
            </template> -->
          </el-table-column>
          <el-table-column
            label="其中：普通推送"
            prop="basePushCount"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            label="其中：升级推送"
            prop="upgradePushCount"
            align="center"
            width="150"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column label="响应规模" align="center">
          <el-table-column
            label="合计"
            prop="pushUpgradeSumCount"
            align="center"
            width="100"
          >
            <!-- <template slot-scope="scope">
              <span v-html="getXiangYing(scope.row)"></span>
            </template> -->
          </el-table-column>
          <el-table-column
            label="其中：普通推送"
            prop="baseReadCount"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            label="其中：升级推送"
            prop="upgradeReadCount"
            align="center"
            width="150"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column label="短信升级规模" prop="shortCount" align="center">
        </el-table-column>
        <el-table-column label="电话升级规模" prop="telCount" align="center">
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <!-- <Pagination
        :total="total"
        :pageNum="pageNum"
        :pageSize="pageSize"
        @pageChange="pageChange"
      /> -->
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      valuetimes: "", //时间段，绑定的时间
      startTime: "", //开始时间
      endTime: "", //结束时间
      dataForm: {
        timeVal: "",
      },
      dataList: [],
      titleList: [], //场景数据
      titleval: null,
      loading: true
    };
  },

  created() {
    // this.fetchTableList();
  },
  activated() {
    this.fetchTableList();
    this.fetchTitleList();
  },
  methods: {
    // 获取表格数据
    fetchTableList() {
      let this_ = this;
      this.loading = true
      console.log(this_.startTime, " this.startTime2");
      console.log(this_.endTime, " this.endTime2");
      this.$http({
        url: this.$http.adornUrl("/cpcplog/getLogTable2"),
        method: "post",
        params: this.$http.adornParams({
          startTime: this_.startTime,
          endTime: this_.endTime,
          activityId: this.titleval,
        }),
      }).then((res) => {
        //   console.log("res",res);
        if (res.data.code === 0) {
          setTimeout(()=>{
            this.loading = false
            this.dataList = res.data.list;
          },1000)
          console.log("ssss", res.data.list);
          
        }else{
          this.$message.error(res.data.msg)
        }
      });
    },
    //  字典获取值
    fetchTitleList() {
      this.$http({
        url: this.$http.adornUrl("/sysdictdata/list"),
        method: "get",
        params: this.$http.adornParams({
          dictType: "du_text",
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.titleList = data.page.list;
        }
      });
    },
    changeTitleCon() {
      // const titleOrContent = this.titleval.split(",");
      console.log("this.titleval", this.titleval);
    },
    //格式化时间
    transformTimestamp(result) {
      const date = new Date(result);
      const Y = date.getFullYear() + "";
      const M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "";
      const D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "";
      // const dateString = Y + "-" + M + "-" + D;
      const dateString = Y + M  + D;
      console.log("dateString", dateString); // > dateString 20200110
      return dateString;
    },
    //查询按钮
    getpolling() {
      // this.getDataList();
      if (!this.valuetimes == "") {
        var time1 = new Date(this.valuetimes[0]).getTime();
        var time2 = new Date(this.valuetimes[1]).getTime();
        const start = this.transformTimestamp(time1);
        const end = this.transformTimestamp(time2);
        this.startTime = start;
        this.endTime = end;
        console.log(this.startTime);
        console.log(this.endTime);
        this.fetchTableList();
      } else {
        this.startTime = "";
        this.endTime = "";
        this.fetchTableList();
      }
    },
    getFaSong(item) {
      let str = "";
      str = parseInt(item.basePushCount) + parseInt(item.upgradePushCount);
      return str;
    },
    getXiangYing(item) {
      let str = "";
      str = parseInt(item.baseReadCount) + parseInt(item.upgradeReadCount);
      return str;
    },
    //导出数据
    exportGet() {
      this.$http({
        url: this.$http.adornUrl("cpcplog/downLogTable2"),
        method: "get",
        params: this.$http.adornParams({
          startTime: this.startTime,
          endTime: this.endTime,
        }),
        responseType: "blob",
      }).then((res) => {
        console.log(res, "ddddddd");
        // return
        if (res.status == 200) {
          //  if(this.code===500){
          //     this.fetchTableList()
          //     return
          //   }else{
          let blob = res.data;
          const fileReader = new FileReader(); // FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件的内容
          fileReader.readAsDataURL(blob); // 开始读取指定的Blob中的内容。一旦完成，result属性中将包含一个data: URL格式的Base64字符串以表示所读取文件的内容
          fileReader.onload = (event) => {
            // 处理load事件。该事件在读取操作完成时触发
            // 新建个下载的a标签，完成后移除。
            let a = document.createElement("a");
            let _fileName = "分公司发送情况查询.xls";
            a.download = _fileName;
            a.href = event.target.result;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
          };
          // }
        }
      });
    },
    //全省数据合计
    // getSummaries(param) {
    //   const { columns, data } = param;
    //   const sums = [];
    //   columns.forEach((column, index) => {
    //     if (index === 0) {
    //       sums[index] = "全省";
    //       return;
    //     }
    //     const values = data.map((item) => Number(item[column.property]));
    //     if (!values.every((value) => isNaN(value))) {
    //       sums[index] = values.reduce((prev, curr) => {
    //         const value = Number(curr);
    //         if (!isNaN(value)) {
    //           return prev + curr;
    //         } else {
    //           return prev;
    //         }
    //       }, 0);
    //       sums[index] += "";
    //     } else {
    //     }
    //   });

    //   return sums;
    // },
    // 分页
    // pageChange(page) {
    //   this.pageSize = page._pageSize;
    //   this.pageNum = page._currentPage;
    //   this.fetchTableList();
    // },
  },
};
</script>
<style scoped lang="scss">
@import "../../../assets/scss/span_color";
.button {
  width: 130px;
  height: 40px;
  background: linear-gradient(to bottom, #4eb5e5 0%, #389ed5 100%); /* W3C */
  border: none;
  border-radius: 5px;
  position: relative;
  border-bottom: 4px solid #2b8bc6;
  color: #fbfbfb;
  font-weight: 600;
  font-family: "Open Sans", sans-serif;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
  font-size: 15px;
  text-align: left;
  text-indent: 5px;
  box-shadow: 0px 3px 0px 0px rgba(0, 0, 0, 0.2);
  cursor: pointer;

  /* Just for presentation */
  // display: block;
  margin: 0 auto;
  margin-bottom: 20px;
}
.button:active {
  box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.2);
  top: 1px;
}

.button:after {
  content: "";
  width: 0;
  height: 0;
  display: block;
  border-top: 20px solid #187dbc;
  border-bottom: 20px solid #187dbc;
  border-left: 16px solid transparent;
  border-right: 20px solid #187dbc;
  position: absolute;
  opacity: 0.6;
  right: 0;
  top: 0;
  border-radius: 0 5px 5px 0;
}

/* Button pointing left */

.button.back {
  text-align: right;
  padding-right: 12px;
  box-sizing: border-box;
}
.button.back:after {
  content: "";
  width: 0;
  height: 0;
  display: block;
  border-top: 20px solid #187dbc;
  border-bottom: 20px solid #187dbc;
  border-right: 16px solid transparent;
  border-left: 20px solid #187dbc;
  position: absolute;
  opacity: 0.6;
  left: 0;
  top: 0;
  border-radius: 5px 0 0 5px;
}

/* Single buttons */

.button.site {
  width: 40px;
  text-align: center;
  text-indent: 0;
}
.button.site:after {
  display: none;
}
/deep/ .el-range-editor--medium .el-range-input {
  background-color: transparent;
  color: white;
}
/deep/ .el-table thead.is-group th {
  background-color: rgb(32, 67, 133);
  // border-bottom: 1px solid #73d2ec;
}
</style>
